﻿using Verse;

namespace ARMIR {
    /// <summary>
    /// 使装备的武器需要身上有特定的装备才能够使用
    /// </summary>
    public class Verb_RequiresEquipment : Verb_Shoot {
        public override bool Available() {
            if (!base.Available())
                return false;

            if (EquipmentSource?.GetComp<Comp_RequiredEquipment>() is Comp_RequiredEquipment comp) {
                bool hasEquipment = CasterPawn != null &&
                                    (CasterPawn.equipment.AllEquipmentListForReading.Any(e =>
                                         e.def == comp.RequiredEquipment) ||
                                     CasterPawn.apparel.WornApparel.Any(a => a.def == comp.RequiredEquipment));
                if (hasEquipment != true) {
                    return false;
                }
            }
            if (CasterPawn != null) {
                if (!CasterPawn.health.hediffSet.HasHediff(DefDatabase<HediffDef>.GetNamed("ARMIR_OriginiumBrainStem"))) {
                    //持有者不是能力者
                    return false;
                }
            }

            return true;
        }
    }
}